{extend name="Common/common" /}

{block name="style"}
<link rel="stylesheet" href="/static_admin/wangEditor/wangEditor.min.css">
<style>
    .layui-form {
        width: 825px;
    }
    #editor {
        height: 630px !important;
    }
    #editor .w-e-text-container {
        height: 600px !important;
    }
    .review img {
        max-width: 200px;
    }
</style>
{/block}

{block name="content"}
<form id="form" class="layui-form" action="{:url('@admin/team/'.$team['id'])}" method="post">
    <input type="hidden" name="_method" value="PUT">
    <div class="layui-form-item">
        <label class="layui-form-label">队伍名称：</label>
        <div class="layui-input-block">
            <input type="text" name="name" value="{$team.name}" required  lay-verify="required" placeholder="请输入队伍名称" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">队伍头像：</label>
        <div class="layui-input-block">
            <button type="button" class="layui-btn layui-btn-primary fileinput-button">
                <span>上传</span>
                <input type="hidden" id="facepic" name="facepic" value="{$team.facepic}">
                <input type="file" name="file" id="file">
            </button>
        </div>
    </div>
    <div class="layui-form-item review">
        <label class="layui-form-label">预览：</label>
        <div class="layui-input-block">
            <img src="{$team.facepic}" alt="">
        </div>
    </div>
    <div class="layui-form-item layui-form-text">
        <label class="layui-form-label">队伍介绍：</label>
        <div class="layui-input-block">
            <input type="hidden" name="content" value="{$team.content}">
            <div id="editor" placeholder="请输入内容"></div>
        </div>
    </div>
    <div class="layui-form-item">
        <div class="layui-input-block">
            <button id="submit" class="layui-btn" lay-submit lay-filter="formDemo">提交</button>
            <button type="button" class="layui-btn layui-btn-primary" onclick="history.back()">返回</button>
        </div>
    </div>
</form>
{/block}

{block name="script"}
<script src="/static_admin/wangEditor/wangEditor.min.js"></script>
<script>
    var E = window.wangEditor;
    var editor = new E('#editor');

    editor.customConfig.uploadImgServer = '{:url("@admin/upload")}';

    editor.create();

    $(function () {

        editor.txt.html($('input[name="content"]').val());


        $('#submit').on('click', function () {
            $('input[name="content"]').val(editor.txt.html())
        })
    });


    layui.use('upload', function () {
        layui.upload.render({
            elem: '#file' //绑定元素
            ,url: '/admin/upload' //上传接口
            ,accept: 'file'
            ,done: function(res){
                //上传完毕回调
                if (res.errno != 0) {
                    layui.alert('上传失败');
                    return false;
                }
                $('#facepic').val(res.data[0]);
                $('.review img').attr('src', $('#facepic').val());
            }
        });
    });

</script>
{/block}